<template>
    <div
        style="background-color: rgb(241, 241, 241);padding:5px;padding-right: 7px;min-height: 100vh; box-sizing: border-box;">
        <van-nav-bar title="添加文章" left-text="返回" left-arrow fixed @click-left="$router.back">

        </van-nav-bar>
        <div style="height: 60px;"></div>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="title" name="title" label="标题" placeholder="标题"
                    :rules="[{ required: true, message: '请填写标题' }]" />

                <van-field v-model="desc" name="desc" label="描述" placeholder="文章描述"
                    :rules="[{ required: true, message: '请输入文章描述' }]" />

                <van-field v-model="pic_url" name="pic_url" rows="2" autosize type="textarea" label="图片" placeholder="图片"
                    :rules="[{ required: true, message: '请输入图片链接' }]" />

                    <van-field v-model="detail" name="detail" rows="10" autosize label="内容" type="textarea" maxlength="1000"
                        placeholder="请输入文章内容" show-word-limit :rules="[{ required: true, message: '请输入文章neirong' }]"/>
                

            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>


    </div>
</template>

<script setup>
import { ref } from 'vue'
import { addArticle } from '../../api';
import {useRouter} from 'vue-router'

let title = ref('')
let desc = ref('')
let pic_url = ref('')
let detail = ref('')
let router = useRouter()

function onSubmit(data) {
   addArticle(data).then(res=>{
    if(res.code==1){
        router.push('/article')
    }
   })
}
</script>

